/* 
 * File:   Enemy.cpp
 * Author: paula
 * 
 * Created on 7 de noviembre de 2014, 14:27
 */

#include "Enemy.h"

Enemy::Enemy() {
}

Enemy::Enemy(int x, int y, SDL_Renderer** gRenderer, int id) : Walker(x, y, gRenderer, id) {

    this->state = WAITING;
    this->loadMediaSnow();
    this->caught = false;
    this->counterEscaping = 1;
    this->escaping = false;

}

Enemy::Enemy(const Enemy& orig) {
}

void Enemy::loadMediaSnow() {

    snow1 = new SBSImage();
    snow2 = new SBSImage();
    snow3 = new SBSImage();
    snow4 = new SBSImage();
    snow5 = new SBSImage();

    snow1->loadMedia(this->path + "/snow" + "/n1.png", &gRenderer);
    snow2->loadMedia(this->path + "/snow" + "/n2.png", &gRenderer);
    snow3->loadMedia(this->path + "/snow" + "/n3.png", &gRenderer);
    snow4->loadMedia(this->path + "/snow" + "/n4.png", &gRenderer);
    snow5->loadMedia(this->path + "/snow" + "/n5.png", &gRenderer);
}

void Enemy::actualize() {

    this->actualizePosition(this->data.x, this->data.y);
    this->actualizeState(this->data.stateCharacter);
    struct Event receivedEvent = this->data.event;
    this->setDirectionRight(this->data.direction);
    switch (this->getState()) {
        case JUMPING:
            this->keepJumping();
            break;
        case KNEELING:
            this->keepKneeling();
            break;
        case FALLING:
            this->keepFallingDown();
            break;
        case WALKING:
            this->keepWalking();
            break;
        case WAITING:
            this->wait();
            break;
        case CAUGHT:
            if (this->escaping) {
                this->keepEscaping();
            } else {
                this->keepCaught();
            }
            break;
        case ESCAPING:
            this->keepEscaping();
            break;
        default:
            this->wait();
            break;
    }
}

void Enemy::actualizeState(int state) {
    switch (state) {
        case JUMPING:
            this->setJumping();
            this->rot = 0;
            break;
        case KNEELING:
            this->setKneeling();
            this->rot = 0;
            break;
        case FALLING:
            this->setFalling();
            this->rot = 0;
            break;
        case WALKING:
            this->setWalking();
            this->rot = 0;
            break;
        case CAUGHT:
            this->setCaught();
            break;
        case ESCAPING:
            this->setEscaping();
            break;
        default:
            this->setWaiting();
            this->rot = 0;
            break;
    }
    this->state = state;
}

void Enemy::setCaught() {
    this->jumping = false;
    this->kneeling = false;
    this->walking = false;
    this->jumping = false;
    this->waiting = false;
    this->fallingDown = false;
    //    this->escaping = false;
    this->caught = true;
}

void Enemy::setEscaping() {
    this->jumping = false;
    this->kneeling = false;
    this->walking = false;
    this->jumping = false;
    this->waiting = false;
    this->fallingDown = false;
    this->caught = false;
    this->escaping = true;
}

void Enemy::keepCaught() {
    switch (this->data.enemyStat) {
            this->rot = 0;
        case (1):
            //            changeImage(snow1, 0);
            this->imageToDraw = snow1;
            break;
        case (2):
            //            changeImage(snow2, 0);
            this->imageToDraw = snow2;
            break;
        case (3):
            //            changeImage(snow3, 0);
            this->imageToDraw = snow3;
            break;
        case (4):
            //            changeImage(snow4, 0);
            this->imageToDraw = snow4;
            break;
        case (5):
            //            changeImage(snow5, 0);
            this->imageToDraw = snow5;
            break;
    }
}

void Enemy::shake(SBSImage* image) {
    switch (this->counterEscaping) {
        case (1):
            //            changeImage(image, 330);
            this->rot = 330;
            this->imageToDraw = image;
            this->counterEscaping++;
            break;
        case (2):
            //            changeImage(image, 30);
            this->rot = 30;
            this->imageToDraw = image;
            this->counterEscaping++;
            break;
        case (3):
            //            changeImage(image, 0);
            this->rot = 0;
            this->imageToDraw = image;
            this->counterEscaping = 1;
            this->escaping = false;
            break;
    }
}

void Enemy::keepEscaping() {
    switch (this->data.enemyStat) {
        case (4):
            this->shake(snow4);
            break;
        case (3):
            this->shake(snow3);
            break;
        case (2):
            this->shake(snow2);
            break;
        case (1):
            this->shake(snow1);
            break;
    }
}

Enemy::~Enemy() {

}